package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysContractRefund;
import com.ruoyi.system.service.ISysContractRefundService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合同退费列Controller
 *
 * @author ruoyi
 * @date 2025-06-29
 */
@RestController
@RequestMapping("/system/refund")
public class SysContractRefundController extends BaseController
{
    @Autowired
    private ISysContractRefundService sysContractRefundService;

    /**
     * 查询合同退费列列表
     */
    //@PreAuthorize("@ss.hasPermi('system:refund:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysContractRefund sysContractRefund)
    {
        startPage();
        List<SysContractRefund> list = sysContractRefundService.selectSysContractRefundList(sysContractRefund);
        return getDataTable(list);
    }

    /**
     * 导出合同退费列列表
     */
    @PreAuthorize("@ss.hasPermi('system:refund:export')")
    @Log(title = "合同退费列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysContractRefund sysContractRefund)
    {
        List<SysContractRefund> list = sysContractRefundService.selectSysContractRefundList(sysContractRefund);
        ExcelUtil<SysContractRefund> util = new ExcelUtil<SysContractRefund>(SysContractRefund.class);
        util.exportExcel(response, list, "合同退费列数据");
    }

    /**
     * 获取合同退费列详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:refund:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysContractRefundService.selectSysContractRefundById(id));
    }

    /**
     * 新增合同退费列
     */
    //@PreAuthorize("@ss.hasPermi('system:refund:add')")
    @Log(title = "合同退费列", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SysContractRefund sysContractRefund)
    {
        return toAjax(sysContractRefundService.insertSysContractRefund(sysContractRefund));
    }

    /**
     * 修改合同退费列
     */
    @PreAuthorize("@ss.hasPermi('system:refund:edit')")
    @Log(title = "合同退费列", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysContractRefund sysContractRefund)
    {
        return toAjax(sysContractRefundService.updateSysContractRefund(sysContractRefund));
    }

    /**
     * 删除合同退费列
     */
    //@PreAuthorize("@ss.hasPermi('system:refund:remove')")
    @Log(title = "合同退费列", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(sysContractRefundService.deleteSysContractRefundById(id));
    }

    /**
     * 校长审核方法
     * @param id
     * @return
     */
    @GetMapping("/approve/{id}")
    public AjaxResult approve(@PathVariable("id")Long id){
        return toAjax(sysContractRefundService.approve(id));
    }

    /**
     * 驳回方法
     */
    @GetMapping("/unApprove/{id}/{note}")
    public AjaxResult unApprove(@PathVariable("id")Long id,@PathVariable("note")String note){
        return toAjax(sysContractRefundService.unApprove(id,note));
    }


}